package src.greedy_algorithms;

import java.util.PriorityQueue;

/**
 * @author starsea
 * @date 2024-08-18 11:25
 */

public class Test {
    public int halveArray(int[] nums) {
        int ans=0;
        double sum=0;
        PriorityQueue<Double> p=new PriorityQueue<>((a, b)-> b.compareTo(a));
        for(int x : nums)
        {
            p.offer((double) x);
            sum+=x;
        }
        double tar=sum/2;
        while(sum>tar)
        {
            double tmp=p.poll();
            tmp/=2;
            sum-=tmp;
            p.offer(tmp);
            ans++;
        }
        return ans;
}
}
